import pandas as pd
from sqlalchemy import create_engine
from app_config import get_engine_ts


def found_amount():
    # 构建查询语句，使用参数化查询
    query = """
           SELECT DISTINCT ts_code, name, fund_type, invest_type, market, benchmark 
           FROM `fund_basic_e` 
           WHERE benchmark LIKE %s
           """
    # 参数
    params = ('沪深300%',)

    # 创建数据库引擎
    engine = get_engine_ts()

    # 执行查询并将结果转换为 DataFrame
    with engine.connect() as connection:
        hs300_fund_e = pd.read_sql_query(query, engine, params=params)

    # 将结果保存到 Excel
    hs300_fund_e.to_excel("fund_basic_e.xlsx", index=False)

    diff = hs300_fund_e['benchmark'].drop_duplicates()
    diff.to_excel("fund_basic_one.xlsx")
    print(diff)


if __name__ == '__main__':
    found_amount()

# 沪深300指数
# 沪深300指数收益率